package com.ruoyi.zyx.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.zyx.mapper.ZyxMemberDeviceMapper;
import com.ruoyi.zyx.domain.ZyxMemberDevice;
import com.ruoyi.zyx.service.IZyxMemberDeviceService;

/**
 * 成员基础信Service业务层处理
 *
 * @author lhs
 * @date 2021-05-31
 */
@Service
public class ZyxMemberDeviceServiceImpl implements IZyxMemberDeviceService
{
    @Autowired
    private ZyxMemberDeviceMapper zyxMemberDeviceMapper;

    /**
     * 查询成员基础信
     *
     * @param id 成员基础信ID
     * @return 成员基础信
     */
    @Override
    public ZyxMemberDevice selectZyxMemberDeviceById(Long id)
    {
        return zyxMemberDeviceMapper.selectZyxMemberDeviceById(id);
    }

    /**
     * 查询成员基础信列表
     *
     * @param zyxMemberDevice 成员基础信
     * @return 成员基础信
     */
    @Override
    public List<ZyxMemberDevice> selectZyxMemberDeviceList(ZyxMemberDevice zyxMemberDevice)
    {
        return zyxMemberDeviceMapper.selectZyxMemberDeviceList(zyxMemberDevice);
    }

    /**
     * 新增成员基础信
     *
     * @param zyxMemberDevice 成员基础信
     * @return 结果
     */
    @Override
    public int insertZyxMemberDevice(ZyxMemberDevice zyxMemberDevice)
    {
        zyxMemberDevice.setCreateTime(DateUtils.getNowDate());
        return zyxMemberDeviceMapper.insertZyxMemberDevice(zyxMemberDevice);
    }

    /**
     * 修改成员基础信
     *
     * @param zyxMemberDevice 成员基础信
     * @return 结果
     */
    @Override
    public int updateZyxMemberDevice(ZyxMemberDevice zyxMemberDevice)
    {
        zyxMemberDevice.setUpdateTime(DateUtils.getNowDate());
        return zyxMemberDeviceMapper.updateZyxMemberDevice(zyxMemberDevice);
    }

    /**
     * 批量删除成员基础信
     *
     * @param ids 需要删除的成员基础信ID
     * @return 结果
     */
    @Override
    public int deleteZyxMemberDeviceByIds(Long[] ids)
    {
        return zyxMemberDeviceMapper.deleteZyxMemberDeviceByIds(ids);
    }

    @Override
    public int addMemberDevice(ZyxMemberDevice zyxMemberDevice)
    {
        List<ZyxMemberDevice> zyxMemberDevices=new ArrayList<>();
        for (Long id : zyxMemberDevice.getIds()) {
            ZyxMemberDevice zyxMemberDeviceIn=new ZyxMemberDevice();
            zyxMemberDeviceIn.setMemberid(zyxMemberDevice.getMemberid());
            zyxMemberDeviceIn.setDeviceid(id);
            zyxMemberDevices.add(zyxMemberDeviceIn);
        }
        return zyxMemberDeviceMapper.batchMemberDevice(zyxMemberDevices);
    }

    /**
     * 删除成员基础信信息
     *
     * @param id 成员基础信ID
     * @return 结果
     */
    @Override
    public int deleteZyxMemberDeviceById(Long id)
    {
        return zyxMemberDeviceMapper.deleteZyxMemberDeviceById(id);
    }

    @Override
    public List<ZyxMemberDevice> memberDeviceTreeselect(Long memberid) {
        return zyxMemberDeviceMapper.memberDeviceTreeselect( memberid);
    }
}
